package com.SSH_Test.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import org.springframework.stereotype.Component;

import com.SSH_Test.pojo.Student;

@Component("studentdao")
public class StudentDao {
	private SessionFactory  sessionFactory;

	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Resource(name="mySessionFactory")
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	public void save(Student student){
		Session session=sessionFactory.openSession();
		session.beginTransaction();
		session.save(student);
		session.getTransaction().commit();	
		}
	public List<Student> listStudent(){
		List<Student> list ;
		Session session=sessionFactory.openSession();
		session.beginTransaction();
		list = session.createQuery("from Student").list();
		//session.getTransaction().commit();
		return list;
	}
}
